from Common.Singleton import *

from FinancialAsset.Cash import Cash
from FinancialAsset.Stock import Stock
from FinancialAsset.Index import Index
from FinancialAsset.Futures import Futures

class AssetFactory(Singleton):
	
	def	import_asset(self, sec_type, ticker):
	
		if not hasattr(self, "asset_container"):
			setattr(self, "asset_container", {})
		
		if not self.asset_container.has_key((sec_type, ticker)):
			self.asset_container[(sec_type, ticker)] = generate_asset(sec_type, ticker)
	
	def acquire_asset(self, sec_type, ticker):
	
		self.import_asset(sec_type, ticker)
		return self.asset_container[(sec_type, ticker)]
		
def generate_asset(sec_type, ticker):
	
	if sec_type == 'CASH':
		return Cash(ticker)
	elif sec_type == 'STOCK':
		return Stock(ticker)
	elif sec_type == 'INDEX':
		return Index(ticker)
	elif sec_type == 'Futures':
		return Futures(ticker)	
	else:
		print 'Err - not defined security type - ' + sec_type	
